package com.jiayang.hhotel.presenter;

import com.jiayang.hhotel.R;
import com.jiayang.hhotel.bean.AccountsListModel;
import com.jiayang.hhotel.bean.Constant;
import com.jiayang.hhotel.bean.InfoModel;
import com.jiayang.hhotel.net.Api;
import com.jiayang.hhotel.ui.AccountsActivity;
import com.jiayang.hhotel.util.LogUtil;
import com.jiayang.hhotel.util.ToastUtil;

import cn.droidlover.xdroidmvp.mvp.XPresent;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.NetError;
import cn.droidlover.xdroidmvp.net.XApi;

/**
 * Created by Administrator on 2017/6/2 0002.
 * 账项页面逻辑类
 */

public class AccountsPresenter extends XPresent<AccountsActivity> {

    /**
     * 获取账项列表
     * @param mpLanguage 语言
     */
    public void getAccountList(int mpLanguage){
        Api.getSetSer().getAccountList(Constant.PHONE,mpLanguage,5)
                .compose(XApi.<AccountsListModel>getApiTransformer())
                .compose(XApi.<AccountsListModel>getScheduler())
                .compose(getV().<AccountsListModel>bindToLifecycle())
                .subscribe(new ApiSubscriber<AccountsListModel>() {
                    @Override
                    protected void onFail(NetError error) {
                        ToastUtil.Toast(getV().getString(R.string.net_error),getV());
                    }

                    @Override
                    public void onNext(AccountsListModel Model) {
                        switch (Model.getState()) {
                            case 9://请求成功
                                getV().setAdapter(Model.getPCashierPayListDtos());
                                break;
                            case -1://失败
                                break;
                            case 1002://没有数据
                                LogUtil.showLog("没有数据");
                                break;
                        }
                    }
                });
    }
}
